package com.project.class3_28.dao.impl;

import com.project.class3_28.bean.StudentBean;
import com.project.class3_28.dao.IStudentDao;

import java.time.LocalDate;
import java.util.List;

public class StudentDaoImpl extends BaseDao implements IStudentDao {
    @Override
    public void add(StudentBean student) {
//        this.updateDB("INSERT INTO t_student(studentName,sex,phone,birthday,email) values(?,?,?,?,?)",
//                student.getStudentName(),student.getSex(),student.getPhone(),student.getBirthday(),student.getEmail());
        this.addEntity(student);
    }

    @Override
    public void del(int id) {
        this.updateDB("delete from t_student where id=?",id);
    }

    @Override
    public void update(int id, String phone) {
        this.updateDB("update t_student set phone=? where id=?",phone,id);
    }

    @Override
    public List<StudentBean> findAll() {
        return this.findDB("select pk_studentId,s_name,s_birthday from t_student ",StudentBean.class);
    }

    @Override
    public List<StudentBean> findByName(String name) {
        return this.findDB("select * from t_student where studentName like ?",StudentBean.class,"%"+name+"%");
    }

    @Override
    public StudentBean findById(int id) {

        return (StudentBean) this.findDB("select * from t_student where id=?",StudentBean.class,id).get(0);
    }

    public static void main(String[] args) {
        IStudentDao dao = new StudentDaoImpl();
        dao.add(new StudentBean("lwx","男","13920398290", LocalDate.parse("1994-09-28"),"3243242@qq.com"));
//        dao.update(7,"15849380493");
//        dao.del(7);
//        System.out.println(dao.findAll());
//        System.out.println(dao.findByName("张"));
//        System.out.println(dao.findById(1));
    }
}
